/**
 * 时间格式化
 */
export const getCurrentTime = (time) => {
  const currentDate = time ? new Date(time) : new Date(Date.now());
  const year = currentDate.getFullYear();
  const month = (currentDate.getMonth() + 1).toString().padStart(2, "0");
  const day = currentDate.getDate().toString().padStart(2, "0");
  const hours = currentDate.getHours().toString().padStart(2, "0");
  const minutes = currentDate.getMinutes().toString().padStart(2, "0");
  const seconds = currentDate.getSeconds().toString().padStart(2, "0");
  const formattedDateTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  return formattedDateTime;
};
/**
 * 获取dom元素路径 找到报错元素
 * //*[@id="root"]/DIV[1]/DIV[2]/BUTTON[1]
 */
export function getPathTo(element) {
  if (element.id !== "") return '//*[@id="' + element.id + '"]';
  if (element === document.body) return element.tagName;
  let ix = 0;
  let siblings = element.parentNode.childNodes;
  for (let i = 0; i < siblings.length; i++) {
    let sibling = siblings[i];
    if (sibling === element)
      return (
        getPathTo(element.parentNode) +
        "/" +
        element.tagName +
        "[" +
        (ix + 1) +
        "]"
      );
    if (sibling.nodeType === 1 && sibling.tagName === element.tagName) ix++;
  }
}
export default { getCurrentTime, getPathTo };
